package fr.generali.accueilclient.gwt.client.state.store;

import com.google.gwt.core.client.Callback;
import com.google.gwt.storage.client.Storage;

import fr.generali.accueilclient.gwt.client.state.StateStore;

/**
 * Simple HTML5 Storage implementation of the state provider.
 */
public class HtmlStorageStateStore implements StateStore {
	private final Storage storage;

	public HtmlStorageStateStore(Storage storage) {
		this.storage = storage;
	}

	@Override
	public void clear(String name) {
		storage.removeItem(name);
	}

	@Override
	public void get(String name, Callback<String, Throwable> callback) {
		callback.onSuccess(storage.getItem(name));
	}

	@Override
	public void set(String name, String value) {
		storage.setItem(name, value);
	}

	@Override
	public void clear() {
		storage.clear();
		
	}

}
